This page last changed on Jul 14, 2009 by sfentress.

Overview

OTrunk Controllers are used link OTrunk objects with Plain Old Java Objects (POJO). The are useful if you want to use OTrunk to configure and save data from java libraries which don't directly use OTrunk objects.

There are 3 objects involved when an controller is used. The OTObject, the OTController, and the "RealObject"(POJO).
A fourth object, OTPackage, is used in order to support plugging in new implementations of the RealObject.

Here is an example of how controllers can be used. There is a java library that supports graphing data. To supply data to the graph a DataProducer interface is implemented and the implementation is passed to the graph. For example lets say we want to provide a DataProducer that always supplies the same value:
SingleValueDataProducer.

Create a OTClass

Make a new java interface which extends OTObjectInterface
Add get and set methods for the properties of the new OTClass

For example:

public interface OTMyObject extends OTObjectInterface {

	public String getMyString();

	public void setMyString(String myString);
}

Create an OTController

Make a new java class which implements OTController
For example:

public class OTMyObjectController extends DefaultOTController {

	public static Class[] realObjectClasses = { MyObject.class };
	public static Class otObjectClass = OTMyObject.class;

	public void loadRealObject(Object realObject) {
		MyObject myObject = (MyObject) realObject;
		OTMyObject otMyObject = (OTMyObject) otObject;

		// property:url
		myObject.setMyString(otMyObject.getMyString());
	}

	public void registerRealObject(Object arg0) {
		// TODO Auto-generated method stub

	}

	public void saveRealObject(Object arg0) {
		// TODO Auto-generated method stub

	}

}

For each controller you need to do the following things:

Declare classes

Define the following two public static fields:

public static Class[] realObjectClasses = { MyObject.class };
public static Class otObjectClass = OTMyObject.class;

Replace MyObject.class with the class this controller is working with.
Replace OTMyObject.class with the OTClass interface created above.

Implement loading code

Implement the "loadRealObject" method. It should get properties from the otObject field, and set them on
the realObject.

Register Controller

There needs to be a OTPackage in the same java package as the OTObject. The name of the OTPackage class
is important it has to follow a convention. OTrunk Package Naming

In the initialize method add a call to register your new controller class:
for example:

public void initialize(OTrunk otrunk) {
  // get controller registry and reistrer our controllers
  OTControllerRegistry registry = (OTControllerRegistry) otrunk.getService(OTControllerRegistry.class);
		
  registry.registerControllerClass(OTPasProjectController.class);
  registry.registerControllerClass(OTPasActivityController.class);

  registry.registerControllerClass(OTDisplayPageController.class);
}
Document generated by Confluence on Jan 27, 2014 16:52